package com.primary.mappers;

import com.primary.controller.dto.ChangePasswordDto;
import com.primary.controller.request.UsersRequest;
import com.primary.entity.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface UsersMapper {

    Users getUserByNameAndPassword(@Param("name") String name,@Param("password") String password);

    List<Users> allusers();

    /**
     * @author Shen Jianhui
     * @date 2023/06/18 Sunday
     * @description This method will provide an entrance to get a new pass,
     *              then user can use it to sign the system
     * @return A new users' Object that can provide to user to Sign in the system
     */
    int registerByNameAndPwd(Users users);

    /**
     * @author Shen Jianhui
     * @date 2023/06/18 Sunday
     * @description To avoid users register their pass could happen a duplicate occurs,
     *              before registering this method will get the username to provide Register Method to check
     * @param name
     * @return A string which is users' name to sign in
     */
    Users getNameForRegister(@Param("name") String name);

    /**
     * @author Shen Jianhui
     * @date 2023/07/15 Saturday
     * @description The param is a Users Object that defining by myself,
     *              if it needs to use it, please GIVE it a Users
     * @return The counts of inserted rows
     */
    int insertOneUser(Users users);

    /**
     * @author Shen Jianhui
     * @date 2023/07/15 Saturday
     * @description To update a User Object, this interface needs an object as its param
     * @return The counts of updated rows
     */
    int updateOneUserById(Users users);

    /**
     * @author Shen Jianhui
     * @date 2023/07/15 Saturday
     * @description In this interface, a method of deleting a Users will be set
     * @return A type of boolean that deleting of result
     */
    int deleteUserById(Integer id);

    /**
     * @author Shen Jianhui
     * @date 2023/07/18 Tuesday
     * @description In this interface, it will to query data by params which/that have passed by BaseRequest that have
     *              two params which are pageNum and pageSize
     * @param usersRequest
     * @updatedate 2023/12/24 Sunday
     * @updatedescrpiption BaseRequest -> UsersRequest
     * @return The result of querying by pages
     */
    List<Map<String, Object>> listByPage(UsersRequest usersRequest);

    /**
     * @author Shen Jianhui
     * @date 2023/07/23 Sunday
     * @description To make sure users' phone or email is unique in the system, it needs to check the phone or email is existing or not
     * @param phone,email
     * @return Having existed or not
     */
    Users getPhoneAndEmailForRegister(@Param("phone") String phone,@Param("email") String email);

    /**
     * @author Shen Jianhui
     * @date 2023/10/22 Sunday
     * @description To provide a method to change password
     * @return The result of changing
     */
    int changePassword(ChangePasswordDto users);
}
